package ursaminor.lazywork.common.core;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import ursaminor.lazywork.platform.model.Account;

public class BaseInterceptor extends BaseController implements HandlerInterceptor {
	
	@Override
	public void afterCompletion(HttpServletRequest req,
			HttpServletResponse resp, Object arg2, Exception arg3)
			throws Exception {
	}

	@Override
	public void postHandle(HttpServletRequest req, HttpServletResponse resp,
			Object arg2, ModelAndView arg3) throws Exception {
		resp.setHeader("P3P", "CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CNOi HIS OUR IND CNT'"); 
		resp.setHeader("Pragma", "No-cache"); 
		resp.setHeader("Cache-Control", "no-cache"); 
		resp.setDateHeader("Expires", 0); 
	}

	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp,
	        Object obj) throws Exception {
		//检查account
		Account account = getCurrentAccount(req);
		if (account==null) {
			req.getRequestDispatcher("/index").forward(req, resp);
			return false;
		}
		return true;
	}
	
}
